﻿//规格化字符
function formatNumber(val, fixed) {
    var number = new Number(val);
    if (number == 0)
        number = "-";
    else
        number = new Number(val).toFixed(fixed)
    return number;
}

//规格化字符 百分比
function formatNumber2(val, fixed, per) {
    var number = new Number(val);

    if (number == 0 || isNaN(number))
        number = "-";
    else
        number = (number * 100).toFixed(fixed) + per;
    return number;
}

//val 源数据, cs 除数, fixed 小数位, un单位, per 替换字
function formatNumber3(val, cs, fixed, un, per) {
    var number = new Number(val);

    if (number == 0 || isNaN(number))
        number = per;
    else
        number = (number / cs).toFixed(fixed) + un;
    return number;
}

//规格化字符 红涨绿跌
//val 数据源
//fixed 小数位
//per 除数
//ud 单位
//rep 替换符号
function UpDown(val, fixed, per, ud, rep) {
    var number = new Number(val);

    if (number == 0 || isNaN(number))
        number = rep;
    else {
        if (number >= 0)
            number = "<span class=\"red\">" + (number * per).toFixed(fixed) + ud + "</span>";
        else
            number = "<span class=\"green\">" + (number * per).toFixed(fixed) + ud + "</span>";
    }
    return number;
}

//规格化字符 红涨绿跌 img
function UpDown2(val, fixed, per, ud, rep) {
    var number = new Number(val);

    if (number == 0 || isNaN(number))
        number = rep;
    else {
        if (number >= 0)
            number = "<span class=\"red\">" + (number * per).toFixed(fixed) + ud + "<img src=\"images/arrow_up.jpg\" /></span>";
        else
            number = "<span class=\"green\">" + (number * per).toFixed(fixed) + ud + "<img src=\"images/arrow_down.jpg\" /></span>";
    }
    return number;
}

//规格化字符 红涨绿跌 
function UpDown3(val,val2, fixed, per, ud, rep) {
    var number = new Number(val2);
    var rel = "-";
    if (number == 0 || isNaN(number))
        rel = rep;
    else {
        if (number >= 0)
            rel = "<span class=\"red\">" + (val * per).toFixed(fixed) + ud + "<img src=\"images/arrow_up.jpg\" /></span>";
        else
            rel = "<span class=\"green\">" + (val * per).toFixed(fixed) + ud + "<img src=\"images/arrow_down.jpg\" /></span>";
    }
    return rel;
}
//规格化字符 红涨绿跌 img
function UpDown4(val, val2, fixed, per, ud, rep) {
    var number = new Number(val2);
    var rel = "-";
    if (number == 0 || isNaN(number))
        rel = rep;
    else {
        if (number >= 0)
            rel = "<span class=\"red\">" + (val * per).toFixed(fixed) + ud + "</span>";
        else
            rel = "<span class=\"green\">" + (val * per).toFixed(fixed) + ud + "</span>";
    }
    return rel;
}

//规格化字符 红涨绿跌 img
function UpDown5(val, val2, fixed, per, ud, rep) {
    var v1 = new Number(val);
    var v2 = new Number(val2);
    var number = new Number(v1-v2);    
    var rel = "-";
    if (number == 0 || isNaN(number))
        rel = rep;
    else {
        if (number >= 0)
            rel = "<span class=\"red\">" + (val * per).toFixed(fixed) + ud + "</span>";
        else
            rel = "<span class=\"green\">" + (val * per).toFixed(fixed) + ud + "</span>";
    }
    return rel;
}

//nc ,s 替换 
function BSImg(nc,s) {
    var rel = s;
    if (nc > 0)
        rel = "<img src=\"images/ico_buy.gif\" />";
    else
        rel = "<img src=\"images/ico_sell.gif\" />";
    return rel; 
}

